package com.masterclient.app.businessmodule.minemodule.contract;

import com.eoner.baselib.enums.FCPageViewState;
import com.eoner.baselibrary.bean.personal.GivingListBean;
import com.masterclient.app.businessmodule.minemodule.api.MineHttpService;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by TMVPHelper on 2018/05/22
 */
public class ActivityListPresenter extends ActivityListContract.Presenter {

    public List<GivingListBean.GivingItemBean> lists = new ArrayList<>();

    @Override
    public void getZsqNoticeList() {
        if (lists.size() == 0) {
            mView.baseShowPageLoading(false);
        }

        Observable<GivingListBean> observable = MineHttpService.getInstance().getNoticeList();
        Disposable disposable = toSubscribe(observable, new Consumer<GivingListBean>() {
            @Override
            public void accept(GivingListBean bean) throws Exception {
                mView.baseHiddenPageLoading();
                mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NORMAL);
                if (Integer.parseInt(bean.getCode()) == 0) {
                    mView.showZsqListData(bean);
                } else {
                    if (lists.size() == 0) {
                        mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NET_ERROR);
                    }
                    mView.showZsqFailed();
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mView.baseHiddenPageLoading();
                if (lists.size() == 0) {
                    mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NET_ERROR);
                }
                mView.showZsqFailed();
                throwable.printStackTrace();
            }
        });

        mRxManager.add(disposable);
    }


}